<?php

tsload(APPS_PATH . '/admin/Lib/Action/AdministratorAction.class.php');

/**
 * 后台部门管理.
 *
 * @author jason
 */
class FashionAction extends AdministratorAction
{
    public $pageTitle = array(
        'index' => '设计师',
    );

    public function _initialize()
    {
        $this->pageTitle['index'] = '时尚圈';
        parent::_initialize();
    }


    /**
     * 公告
     */
    public function notice()
    {

        //搜索区别
        $_POST['rec'] = $isRec = isset($_REQUEST['rec']) ? t($_REQUEST['rec']) : 1;
        if (!$isRec) {
            $_POST['is_audit'] = $isRec = isset($_REQUEST['is_audit']) ? t($_REQUEST['is_audit']) : $isRec;
        }

        $this->pageKeyList = array('notice_id', 'title','updated', 'uid', 'DOACTION');

        //TODO 临时写死
        $this->pageTab[] = array('title' => '公告管理', 'tabHash' => 'index', 'url' => U('admin/Fashion/notice'));
        $this->pageTab[] = array('title' => '添加公告', 'tabHash' => 'addNotice', 'url' => U('admin/Fashion/addNotice'));

        //$this->pageButton[] = array('title' => L('PUBLIC_DYNAMIC_SEARCH'), 'onclick' => "admin.fold('search_form')");
        $this->pageButton[] = array('title' => '删除', 'onclick' => "admin.FashionEdit('','delNotice','" . L('PUBLIC_STREAM_DELETE') . "','" . L('PUBLIC_DYNAMIC') . "')");


        $isRec == 1 && $_REQUEST['tabHash'] = 'rec';
        $_REQUEST['tabHash'] = 'unAudit';
        $this->assign('pageTitle', $isRec ? L('PUBLIC_RECYCLE_BIN') : L('PUBLIC_DYNAMIC_MANAGEMENT'));
        $map['is_del'] = $isRec == 1 ? 1 : 0;
        if (!$isRec) {
            //$map['is_audit'] = $is_audit == 1 ? 1 : 0;
        }


        $listData = model('Notice')->getList();
//        var_dump(model('notice'));
//        echo model('notice')->getLastSql();
//        dump($listData);
        foreach ($listData['data'] as &$v) {
            $img = getImageUrlByAttachId($v['picture']);
            $v['picture'] = '<img src="' . $img . '" width="50px"  height="50px"/>';
            $v['is_audit'] = $v['is_audit'] && $v['is_audit'] == 1 ? '审核通过' : '审核不通过';
            $v['updated'] = date("Y-m-d H:i:s",$v['updated']);
            $v['uid'] = D('User')->where(array('uid'=>$v['uid']))->getField('uname',false)[0];
            $v['DOACTION'] = '<a href="' . U('admin/Fashion/editNotice', array('tabHash' => 'editNotice', 'notice_id' => $v['notice_id'])) . '">' . L('PUBLIC_EDIT') . '</a> ' . "<a href='javascript:void(0)' onclick='admin.FashionEdit({$v['notice_id']},\"delNotice\",\"" . L('PUBLIC_STREAM_DELETE') . '","' . L('PUBLIC_DYNAMIC') . "\")'>" . L('PUBLIC_STREAM_DELETE') . '</a>';
        }
        $this->_listpk = 'notice_id';
        $this->displayList($listData);
    }


    /**
     * 添加公告.
     */
    public function addNotice()
    {

        $notice_rs[0] = '请选择';
        $this->assign('pageTitle', '添加公告');
        $this->pageTab[] = array('title' => '公告管理', 'tabHash' => 'list', 'url' => U('admin/Fashion/notice'));
        $this->pageTab[] = array('title' => '添加公告', 'tabHash' => 'addNotice', 'url' => U('admin/Fashion/addNotice'));
        $this->pageKeyList = array('title', 'content', 'uid');
        $notice = m('notice')->where(array('isdel' => 0))->select();
        if ($notice) {
            foreach ($notice as $v) {
                $notice_rs[$v['id']] = $v['name'];
            }
        }

        $this->opt['notice_id'] = $notice_rs;
        $this->opt['is_top'] = array('1' => '是', '0' => '否');
        $this->opt['is_audit'] = array('1' => '审核通过', '0' => '审核不通过');
        $this->opt['state'] = array('1' => '正常', '0' => '删除');
        $this->notEmpty = array('title','content');
        // 表单URL设置
        $this->savePostUrl = U('admin/Fashion/doAddNotice');
        //$this->onsubmit = 'admin.newsCheck(this)';
        $this->onload[] = "$('#search_ids').val('');";
        $this->displayConfig();
    }

    /**
     * 执行添加公告.
     */
    public function doAddNotice()
    {
        t($_POST['title']) == '' && $this->error('请填写公告标题');
        t($_POST['content']) == '' && $this->error('请填写公告内容');

        $map['title'] = t($_POST['title']);
        if (model('Notice')->where($map)->find()) {
            $this->error('此公告已存在');
        }
        $insertData['title'] = trim($_POST['title']);
        $insertData['sort'] = empty($_POST['sort']) ? 100 : intval($_POST['sort']);
        $insertData['created'] = time();
        $insertData['updated'] = time();
        $insertData['content'] = $_POST['content'];
        $insertData['uid'] = $this->uid;
        $insertData['state'] = !empty($_POST['state']) ? intval($_POST['state']) : 1;

        $res = model('notice')->add($insertData);
        if ($res) {
            $this->assign('jumpUrl', U('admin/Fashion/notice'));
            $this->success(L('PUBLIC_ADD_SUCCESS'));
        } else {
            $this->error(model('Notice')->getError());
        }
    }

    /**
     * 编辑公告页面.
     */
    public function editNotice()
    {
        $notice_id = intval($_REQUEST['notice_id']);
        $this->pageTab[] = array('title' => '公告管理', 'tabHash' => 'notice', 'url' => U('admin/Fashion/notice'));
        //$this->pageTab[] = array('title' => '添加设计师', 'tabHash' => 'addDesign', 'url' => U('admin/design/addDesign'));
        $this->pageTab[] = array('title' => '编辑公告', 'tabHash' => 'editNotice', 'url' => "#");
//        $this->pageTab[] = array('title' => '添加设计师作品', 'tabHash' => 'addArticle', 'url' => U('admin/design/addArticle',['design_id'=>$design_id]));
        // 列表key值 DOACTION表示操作
        $this->pageKeyList = array('notice_id', 'title', 'content', 'uid');
        $this->opt['type'] = array('2' => L('PUBLIC_SYSTEM_FIELD'));
        $this->opt['is_top'] = array('1' => '是', '0' => '否');
        $this->opt['is_audit'] = array('1' => '审核通过', '0' => '审核不通过');
        $this->opt['state'] = array('1' => '正常', '0' => '删除');
        // 字段选项配置
        $this->opt['is_recommend'] = array('1' => '是', '0' => '否');
        //获取用户资料

        $noticeInfo = model('Notice')->getOneyById($notice_id);
//        $brand = m('brand')->where(['isdel'=>0])->select();
//        if($brand){
//            foreach($brand as $v){
//                $brand_rs[$v['id']] = $v['name'];
//            }
//        }
//        $this->opt['brand_id'] = $brand_rs;
        $map['state'] = array('neq', 1);
        //$this->opt['user_category'] = model('News')->getAllHash($map);

        if (!$noticeInfo) {
            $this->error(L('PUBLIC_GET_INFORMATION_FAIL'));
        }
        $rs = model('Notice')->where('notice_id=' . $notice_id)->find();

        $noticeInfo['picture'] = intval($rs['picture']);
        $this->assign('pageTitle', '编辑公告');
        $this->savePostUrl = U('admin/Fashion/doUpdateNotice');

        $this->displayConfig($noticeInfo);
    }


    /**
     * 执行更新公告
     */
    public function doUpdateNotice()
    {
        t($_POST['title']) == '' && $this->error('标题不能为空');

        $map['notice_id'] = ($_POST['notice_id']);
        if (!model('Notice')->where($map)->find()) {
            $this->error('此公告不存在');
        }
        $updateData['title'] = trim($_POST['title']);
        $updateData['sort'] = empty($_POST['sort']) ? 100 : intval($_POST['sort']);
        $updateData['updated'] = time();
        $updateData['content'] = $_POST['content'];
        $updateData['uid'] = !empty($_POST['uid']) ? intval($_POST['uid']) : 0;
        $updateData['state'] = !empty($_POST['state']) ? intval($_POST['state']) : 1;
        $res = model('Notice')->where($map)->save($updateData);

        if ($res) {
            //$this->assign('jumpUrl', U('admin/Content/news'));
            $this->success('编辑成功');
        } else {
            $this->error(model('Notice')->getError());
        }
    }


    /**
     * 删除公告
     */
    public function delNotice()
    {
        $id = ($_POST['id']);
        $map = [];
        if ($id && is_array($id)) {
            $map['notice_id'] = ['in' => implode(',', $id)];
            $data['state'] = 0;
            foreach ($id as $v) {
                $map['notice_id'] = $v;
                $res = D('notice')->where($map)->save($data);
            }

        } else {
            $map['notice_id'] = $id;
            $data['state'] = 0;
            $res = D('notice')->where($map)->save($data);
        }

        if ($res) {
            $this->assign('jumpUrl', U('admin/Fashion/notice'));
            $return['data'] = L('PUBLIC_DELETE_SUCCESS');
        } else {
            $return['data'] = L('PUBLIC_DELETE_FAIL');
        }
        echo json_encode($return);
        exit();

    }

//======================================================================================================================


    /**
     * 新品
     */
    public function product()
    {
        //搜索区别
        $_POST['rec'] = $isRec = isset($_REQUEST['rec']) ? t($_REQUEST['rec']) : 1;
        if (!$isRec) {
            $_POST['is_audit'] = $isRec = isset($_REQUEST['is_audit']) ? t($_REQUEST['is_audit']) : $isRec;
        }

        $this->pageKeyList = array('title','picture','out_link', 'uid','updated', 'DOACTION');

        //TODO 临时写死
        $this->pageTab[] = array('title' => '新品管理', 'tabHash' => 'index', 'url' => U('admin/Fashion/product'));
        $this->pageTab[] = array('title' => '添加新品', 'tabHash' => 'addProduct', 'url' => U('admin/Fashion/addProduct'));

        //$this->pageButton[] = array('title' => L('PUBLIC_DYNAMIC_SEARCH'), 'onclick' => "admin.fold('search_form')");
        $this->pageButton[] = array('title' => '删除', 'onclick' => "admin.FashionEdit('','delProduct','" . L('PUBLIC_STREAM_DELETE') . "','" . L('PUBLIC_DYNAMIC') . "')");


        $isRec == 1 && $_REQUEST['tabHash'] = 'rec';
        $_REQUEST['tabHash'] = 'unAudit';
        $this->assign('pageTitle', $isRec ? L('PUBLIC_RECYCLE_BIN') : L('PUBLIC_DYNAMIC_MANAGEMENT'));
        $map['is_del'] = $isRec == 1 ? 1 : 0;
        if (!$isRec) {
            //$map['is_audit'] = $is_audit == 1 ? 1 : 0;
        }


        $listData = model('Product')->getList();
//        var_dump(model('product'));
//        echo model('product')->getLastSql();
//        dump($listData);
        foreach ($listData['data'] as &$v) {
            $img = getImageUrlByAttachId($v['picture']);
            $v['picture'] = '<img src="' . $img . '" width="50px"  height="50px"/>';
            $v['is_audit'] = $v['is_audit'] && $v['is_audit'] == 1 ? '审核通过' : '审核不通过';
            $v['updated'] = date("Y-m-d H:i:s",$v['updated']);
            $v['DOACTION'] = '<a href="' . U('admin/Fashion/editproduct', array('tabHash' => 'editproduct', 'product_id' => $v['product_id'])) . '">' . L('PUBLIC_EDIT') . '</a> ' . "<a href='javascript:void(0)' onclick='admin.FashionEdit({$v['product_id']},\"delProduct\",\"" . L('PUBLIC_STREAM_DELETE') . '","' . L('PUBLIC_DYNAMIC') . "\")'>" . L('PUBLIC_STREAM_DELETE') . '</a>';
        }

        $this->_listpk = 'product_id';
        $this->displayList($listData);
    }


    /**
     * 添加产品.
     */
    public function addProduct()
    {
        $product_rs[0] = '请选择';
        $this->assign('pageTitle', '添加新品');
        $this->pageTab[] = array('title' => '新品管理', 'tabHash' => 'list', 'url' => U('admin/Fashion/product'));
        $this->pageTab[] = array('title' => '添加新品', 'tabHash' => 'addProduct', 'url' => U('admin/Fashion/addProduct'));
        $this->pageKeyList = array('title','picture', 'out_link', 'uid');
        $product = m('Product')->where(array('is_del' => 0))->select();
        if ($product) {
            foreach ($product as $v) {
                $product_rs[$v['id']] = $v['name'];
            }
        }

        $this->opt['product_id'] = $product_rs;
        $this->opt['is_top'] = array('1' => '是', '0' => '否');
        $this->opt['is_audit'] = array('1' => '审核通过', '0' => '审核不通过');
        $this->opt['state'] = array('1' => '正常', '0' => '删除');
        $this->notEmpty = array('news_title');
        // 表单URL设置
        $this->savePostUrl = U('admin/Fashion/doAddProduct');
        $this->onsubmit = 'admin.checkTitle(30)';
        //$this->onsubmit = 'admin.newsCheck(this)';
        $this->onload[] = "$('#search_ids').val('');";
        $this->displayConfig();
    }

    /**
     * 执行添加产品.
     */
    public function doAddProduct()
    {
        t($_POST['title']) == '' && $this->error('标题不能为空');
        $map['title'] = t($_POST['title']);
        if (model('Product')->where($map)->find()) {
            $this->error('此新品已存在');
        }
        $insertData['title'] = trim($_POST['title']);
        $insertData['picture'] = intval($_POST['picture']);
        $insertData['sort'] = empty($_POST['sort']) ? 100 : intval($_POST['sort']);
        $insertData['created'] = time();
        $insertData['updated'] = time();
        $insertData['out_link'] = trim($_POST['out_link']);
        $insertData['uid'] = !empty($_POST['uid']) ? intval($_POST['uid']) : 0;
        $insertData['state'] = !empty($_POST['state']) ? intval($_POST['state']) : 1;
        $insertData['is_del'] = 0;
        $res = model('Product')->add($insertData);

        if ($res) {
            $this->assign('jumpUrl', U('admin/Fashion/product'));
            $this->success(L('PUBLIC_ADD_SUCCESS'));
        } else {
            $this->error(model('Product')->getError());
        }
    }

    /**
     * 编辑产品页面.
     */
    public function editProduct()
    {
        $product_id = intval($_REQUEST['product_id']);
        $this->pageTab[] = array('title' => '新品管理', 'tabHash' => 'product', 'url' => U('admin/Fashion/product'));
        //$this->pageTab[] = array('title' => '添加设计师', 'tabHash' => 'addDesign', 'url' => U('admin/design/addDesign'));
        $this->pageTab[] = array('title' => '编辑新品', 'tabHash' => 'editProduct', 'url' => "#");
//        $this->pageTab[] = array('title' => '添加设计师作品', 'tabHash' => 'addArticle', 'url' => U('admin/design/addArticle',['design_id'=>$design_id]));
        // 列表key值 DOACTION表示操作
        $this->pageKeyList = array('product_id','picture','title', 'out_link', 'uid');
        $this->opt['type'] = array('2' => L('PUBLIC_SYSTEM_FIELD'));
        $this->opt['is_top'] = array('1' => '是', '0' => '否');
        $this->opt['is_audit'] = array('1' => '审核通过', '0' => '审核不通过');
        $this->opt['state'] = array('1' => '正常', '0' => '删除');
        // 字段选项配置
        $this->opt['is_recommend'] = array('1' => '是', '0' => '否');
        //获取用户资料

        $productInfo = model('Product')->getOneyById($product_id);
//        $brand = m('brand')->where(['isdel'=>0])->select();
//        if($brand){
//            foreach($brand as $v){
//                $brand_rs[$v['id']] = $v['name'];
//            }
//        }
//        $this->opt['brand_id'] = $brand_rs;
        $map['state'] = array('neq', 1);
        //$this->opt['user_category'] = model('News')->getAllHash($map);

        if (!$productInfo) {
            $this->error(L('PUBLIC_GET_INFORMATION_FAIL'));
        }
        $rs = model('Product')->where('product_id=' . $product_id)->find();

        $productInfo['picture'] = intval($rs['picture']);
        $this->assign('pageTitle', '编辑新品');
        $this->savePostUrl = U('admin/Fashion/doUpdateProduct');

        $this->displayConfig($productInfo);
    }


    /**
     * 执行更新产品
     */
    public function doUpdateProduct()
    {
        t($_POST['title']) == '' && $this->error('标题不能为空');

        $map['product_id'] = ($_POST['product_id']);
        if (!model('Product')->where($map)->find()) {
            $this->error('此新品不存在');
        }
        $updateData['title'] = trim($_POST['title']);
        $updateData['sort'] = empty($_POST['sort']) ? 100 : intval($_POST['sort']);
        $updateData['updated'] = time();
        $updateData['out_link'] = $_POST['out_link'];
        $updateData['uid'] = !empty($_POST['uid']) ? intval($_POST['uid']) : 0;
        $updateData['state'] = !empty($_POST['state']) ? intval($_POST['state']) : 1;
        $res = model('Product')->where($map)->save($updateData);

        if ($res) {
            //$this->assign('jumpUrl', U('admin/Content/news'));
            $this->success('编辑成功');
        } else {
            $this->error(model('Product')->getError());
        }
    }


    /**
     * 删除产品
     */
    public function delProduct()
    {
        $id = ($_POST['id']);
        $map = [];
        if ($id && is_array($id)) {
            $map['product_id'] = ['in' => implode(',', $id)];
            $data['state'] = 0;
            foreach ($id as $v) {
                $map['product_id'] = $v;
                $res = D('product')->where($map)->save($data);
            }

        } else {
            $map['product_id'] = $id;
            $data['state'] = 0;
            $res = D('product')->where($map)->save($data);
        }

        if ($res) {
            $this->assign('jumpUrl', U('admin/Fashion/product'));
            $return['data'] = L('PUBLIC_DELETE_SUCCESS');
        } else {
            $return['data'] = L('PUBLIC_DELETE_FAIL');
        }
        echo json_encode($return);
        exit();

    }


//=====================================================================================================================


    public function addArticle()
    {
        $design_id = ($_GET['design_id']);
        if (!$design_id) {
            $this->error('此设计师不存在');
        } else {
            $map['design_id'] = $design_id;
            $rs = model('Design')->where(['design_id' => $design_id])->find();

            if (!$rs) {
                $this->error('此设计师不存在');
            }
        }
        $this->pageKeyList = array('article_id', 'title', 'design_id', 'pictures', 'info', 'is_audit', 'state', 'sort', 'is_top');
        $this->pictures = 1;
        $info['design_id'] = $design_id;
        $this->opt['is_top'] = array('1' => '是', '0' => '否');
        $this->opt['is_audit'] = array('1' => '审核通过', '0' => '审核不通过');
        $this->opt['state'] = array('1' => '正常', '0' => '删除');
        $this->notEmpty = array('news_title');
        // 表单URL设置
        $this->savePostUrl = U('admin/design/doAddDesignArticle');
        $this->assign('hasPictures', 1);
        $this->displayConfig($info);
    }



    public function design()
    {
        //搜索区别
        $_POST['rec'] = $isRec = isset($_REQUEST['rec']) ? t($_REQUEST['rec']) : 1;
        if (!$isRec) {
            $_POST['is_audit'] = $isRec = isset($_REQUEST['is_audit']) ? t($_REQUEST['is_audit']) : $isRec;
        }

        $this->pageKeyList = array('design_id', 'name', 'brand_name', 'picture', 'intro');

        //TODO 临时写死
        $this->pageTab[] = array('title' => '设计师管理', 'tabHash' => 'index', 'url' => U('admin/design/index'));
//        $this->pageTab[] = array('title' => '添加设计师', 'tabHash' => 'addDesign', 'url' => U('admin/design/addDesign'));

        //$this->pageButton[] = array('title' => L('PUBLIC_DYNAMIC_SEARCH'), 'onclick' => "admin.fold('search_form')");
        $this->pageButton[] = array('title' => '删除', 'onclick' => "admin.ContentEdit('','delDesign','" . L('PUBLIC_STREAM_DELETE') . "','" . L('PUBLIC_DYNAMIC') . "')");


        $isRec == 1 && $_REQUEST['tabHash'] = 'rec';
        $_REQUEST['tabHash'] = 'unAudit';
        $this->assign('pageTitle', $isRec ? L('PUBLIC_RECYCLE_BIN') : L('PUBLIC_DYNAMIC_MANAGEMENT'));
        $map['is_del'] = $isRec == 1 ? 1 : 0;
        if (!$isRec) {
            //$map['is_audit'] = $is_audit == 1 ? 1 : 0;
        }


        $listData = model('Design')->getList();

        foreach ($listData['data'] as &$v) {
            if ($v['brand_id'] > 0) {
                $brand_rs = m('brand')->field('name')->where(['id' => $v['brand_id']])->find();
                $v['brand_name'] = $brand_rs['name'];
            } else {
                $v['brand_name'] = '';
            }
            $img = getImageUrlByAttachId($v['picture']);
            $v['picture'] = '<img src="' . $img . '" width="50px"  height="50px"/>';;
//            $v['is_audit'] = $v['is_audit'] && $v['is_audit'] == 1 ? '审核通过' : '审核不通过';;
//            if ($isRec == 0) {
//                $v['DOACTION'] = '';
//                $v['DOACTION'] = '<a href="' . U('admin/design/editDesign', array('tabHash' => 'editDesign', 'design_id' => $v['design_id'])) . '">' . L('PUBLIC_EDIT') . '</a> ' . '<a href="' . U('admin/design/editDesign', array('tabHash' => 'editDesign', 'design_id' => $v['design_id'])) . '">' . L('PUBLIC_EDIT') . '</a> ' . "<a href='javascript:void(0)' onclick='admin.DesignEdit({$v['design_id']},\"delDesign\",\"" . L('PUBLIC_STREAM_DELETE') . '","' . L('PUBLIC_DYNAMIC') . "\")'>" . L('PUBLIC_STREAM_DELETE') . '</a>';
//            } else {
//                $v['DOACTION'] = '<a href="' . U('admin/design/articleList', array('tabHash' => 'articleList', 'design_id' => $v['design_id'])) . '">设计师图集</a> ' . '<a href="' . U('admin/design/editDesign', array('tabHash' => 'editDesign', 'design_id' => $v['design_id'])) . '">' . L('PUBLIC_EDIT') . '</a> ' . "<a href='javascript:void(0)' onclick='admin.DesignEdit({$v['design_id']},\"delDesign\",\"" . L('PUBLIC_STREAM_DELETE') . '","' . L('PUBLIC_DYNAMIC') . "\")'>" . L('PUBLIC_STREAM_DELETE') . '</a>';
//            }
        }

        $this->_listpk = 'design_id';
        $this->displayList($listData);
    }


    public function editArticle()
    {
        $article_id = intval($_REQUEST['article_id']);
        $this->pageTab[] = array('title' => '设计师管理', 'tabHash' => 'index', 'url' => U('admin/design/index'));
        $this->pageTab[] = array('title' => '编辑设计师作品', 'tabHash' => 'addArticle', 'url' => U('admin/design/addArticle', ['article_id' => $article_id]));

        $this->pageKeyList = array('article_id', 'title', 'design_id', 'pictures', 'info', 'is_audit', 'state', 'sort', 'is_top');
        $this->opt['type'] = array('2' => L('PUBLIC_SYSTEM_FIELD'));
        $this->opt['is_top'] = array('1' => '是', '0' => '否');
        $this->opt['is_audit'] = array('1' => '审核通过', '0' => '审核不通过');
        $this->opt['state'] = array('1' => '正常', '0' => '删除');
        //获取资料
        $articleInfo = model('DesignArticle')->where(['article_id' => $article_id])->find();
        $map['state'] = array('neq', 1);
        //$this->opt['user_category'] = model('News')->getAllHash($map);

        if (!$articleInfo) {
            $this->error('获取信息失败');
        }

        $this->assign('pageTitle', '编辑设计师图片');
        $this->savePostUrl = U('admin/design/doUpdateDesignArticle');
        $this->assign('hasPictures', 1);
        $this->displayConfig($articleInfo);
    }


//编辑设计师图片集
    public function doUpdateDesignArticle()
    {
        $article_id = ($_POST['article_id']);
        if (!$article_id) {
            $this->error('此设计师图集不存在');
        } else {

            $rs = model('DesignArticle')->where(['article_id' => $article_id])->find();
            if (!$rs) {
                $this->error('此设计师图集不存在!');
            }
        }

        $pictures = [];
        if ($_POST['pictures']) {
            foreach ($_POST['pictures'] as $v) {
                if ($v) {
                    $pictures[] = $v;
                }
            }
        }
        $updateData['title'] = $_POST['title'];
        $updateData['pictures'] = implode('|', $pictures);
        $updateData['sort'] = intval($_POST['sort']);
        $updateData['info'] = $_POST['info'];
        $updateData['is_top'] = $_POST['is_top'];
        $updateData['state'] = $_POST['state'];
        $updateData['is_audit'] = $_POST['is_audit'];
        $res = model('DesignArticle')->where(['article_id' => $article_id])->save($updateData);

        if ($res) {
            $this->assign('jumpUrl', U('admin/design/index'));
            $this->success('保存成功');
        } else {
            $this->error(model('DesignArticle')->getError());
        }
    }


    public function articleList()
    {
        $isRec = 0;
        $design_id = trim($_GET['design_id']);
        $rs = model('Design')->where(['design_id' => $design_id])->find();
        if (!$rs) {
            $this->error('此设计师不存在!');
        }
        $this->pageKeyList = array('design_id', 'design_name', 'title', 'picture', 'sort', 'is_audit', 'DOACTION');

        //TODO 临时写死
        $this->pageTab[] = array('title' => '设计师管理', 'tabHash' => 'index', 'url' => U('admin/design/index'));
        $this->pageButton[] = array('title' => '删除', 'onclick' => "admin.delArticle('','delArticle','" . L('PUBLIC_STREAM_DELETE') . "','" . L('PUBLIC_DYNAMIC') . "')");

        $listData = model('DesignArticle')->getList(20, $design_id);

        foreach ($listData['data'] as &$v) {
            $many = $v['pictures'];
            $many_2 = '';
            if ($many && stripos($many, '|')) {
                $many_ = explode('|', $many);
                $many_2 = $many_[0];
            } else if ($many) {
                $many_2 = $many;
            }
            $v['design_name'] = $rs['name'];
            $img = getImageUrlByAttachId($many_2);
            $v['picture'] = '<img src="' . $img . '" width="50px"  height="50px"/>';;
            $v['is_audit'] = $v['is_audit'] && $v['is_audit'] == 1 ? '审核通过' : '审核不通过';;
            if ($isRec == 0) {
                $v['DOACTION'] = '';
                $v['DOACTION'] = '<a href="' . U('admin/design/editArticle', array('tabHash' => 'editDesign', 'article_id' => $v['article_id'])) . '">' . L('PUBLIC_EDIT') . '</a> ' . "<a href='javascript:void(0)' onclick='admin.delArticle({$v['article_id']},\"delArticle\",\"" . L('PUBLIC_STREAM_DELETE') . '","' . L('PUBLIC_DYNAMIC') . "\")'>" . L('PUBLIC_STREAM_DELETE') . '</a>';
            } else {
                $v['DOACTION'] = '<a href="' . U('admin/design/editArticle', array('tabHash' => 'editDesign', 'article_id' => $v['article_id'])) . '">' . L('PUBLIC_EDIT') . '</a> ' . "<a href='javascript:void(0)' onclick='admin.delArticle({$v['article_id']},\"delArticle\",\"" . L('PUBLIC_STREAM_DELETE') . '","' . L('PUBLIC_DYNAMIC') . "\")'>" . L('PUBLIC_STREAM_DELETE') . '</a>';
            }
        }

        $this->_listpk = 'article_id';
        $this->displayList($listData);
    }

    public function delArticle()
    {
        $article_id = ($_POST['id']);
        $map = [];
        $res = model('DesignArticle')->where(['article_id' => $article_id])->find();//获取
        if ($article_id && is_array($article_id)) {
            //$map['article_id'] = ['in'=> implode(',',$article_id)  ] ;
            $data['state'] = 0;
            foreach ($article_id as $v) {
                $map['article_id'] = $v;
                $res = model('DesignArticle')->where($map)->delete();
            }

        } else {
            $map['article_id'] = $article_id;
            $data['state'] = 0;
            $res = model('DesignArticle')->where($map)->delete();
        }

        if ($res) {
            $this->assign('jumpUrl', U('admin/Design/articleList', ['design_id' => $res['design_id']]));
            $return['data'] = L('PUBLIC_DELETE_SUCCESS');
        } else {
            $return['data'] = L('PUBLIC_DELETE_FAIL');
        }
        echo json_encode($return);
        exit();
    }

    public function doAddDesignArticle()
    {
        $design_id = ($_POST['design_id']);
        if (!$design_id) {
            $this->error('此设计师不存在');
        } else {
            $rs = model('Design')->where(['design_id' => $design_id])->find();
            if (!$rs) {
                $this->error('此设计师不存在!');
            }
        }
        $pictures = [];
        if ($_POST['pictures']) {
            foreach ($_POST['pictures'] as $v) {
                if ($v) {
                    $pictures[] = $v;
                }
            }
        }
        $insertData['title'] = $_POST['title'];
        $insertData['pictures'] = implode('|', $pictures);
        $insertData['addtime'] = time();
        $insertData['sort'] = intval($_POST['sort']);
        $insertData['info'] = $_POST['info'];
        $insertData['design_id'] = $_POST['design_id'];
        $insertData['is_top'] = $_POST['is_top'];
        $insertData['state'] = $_POST['state'];
        $insertData['is_audit'] = $_POST['is_audit'];
        $res = model('DesignArticle')->add($insertData);
        if ($res) {
            $this->assign('jumpUrl', U('admin/design/index'));
            $this->success('保存成功');
        } else {
            $this->error(model('news')->getError());
        }
    }

}